package com.mlz.mlzmall.ui.dialog;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.mlz.mlzmall.R;


/**
 * 弹窗
 */
public class CallDialog {
    public static View pw;
    public static PopupWindow pWindow;
    private static Button call;
    private static Button cancel;
    private static Button btn_cancel;
    private LinearLayout rl_call_center;

    public static void call(final Context context, final String str) {
        //  退出对话框
        pw = LayoutInflater.from(context).inflate(R.layout.dialog_call, null);
        call = (Button) pw.findViewById(R.id.btn_call_center);
        btn_cancel = (Button) pw.findViewById(R.id.btn_cancel);
        cancel = (Button) pw.findViewById(R.id.btn_cancel_center);
        pWindow = new PopupWindow(pw, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);//弹框显示大小
        pWindow.setFocusable(true);
        pWindow.setBackgroundDrawable(new ColorDrawable(0x55000000));//设置背景为透明

      //  pWindow.setAnimationStyle(R.style.AnimationBottom);
        pWindow.showAtLocation(pw, Gravity.BOTTOM, 0, 0);
        call.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + str));
                if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                    return;
                }
                context.startActivity(intent);
                pWindow.dismiss();
            }
        });
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pWindow.dismiss();
            }
        });
        btn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pWindow.dismiss();
            }
        });
    }
}
